package com.spr.gw.handler;

import com.spr.gw.common.ResponseCode;
import com.spr.gw.common.ResultBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 定义统一异常处理类 --lsy
 */
@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultBean handle(Exception e){
        if(e instanceof Exception){
            e.printStackTrace();
            return ResultBean.createByCodeMessage(ResponseCode.EXCEPTION.getCode(),
                    "服务器发生异常",e.getMessage());
        }
        return ResultBean.createByCodeMessage(ResponseCode.EXCEPTION.getCode(),
                "未知错误");
    }
}
